﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CentaLine.Model;
using CentaLine.Repository;

namespace CentaLine.Site.Controllers
{
    public class VitualPhoneController : BaseController
    {
        DirectorManager dm;
        VitualPhoneManager vp;
        public VitualPhoneController()
        {
            dm = new DirectorManager();
            vp = new VitualPhoneManager();
        }
        //
        // GET: /VitualPhone/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetVitualPhoneList(int page = 1, int pageSize = 15, string directorId = null)
        {
            int skip = (page - 1) * pageSize;
            var res = vp.GetVitualPhoneDesList(DateTime.Now, directorId).Skip(skip).Take(pageSize);
            return Json(res);
        }

        public ActionResult GetVitualPhoneListCount(string directorId = null)
        {
            var res = vp.GetVitualPhoneDesList(DateTime.Now, directorId).Count;
            return Json(res);
        }

        public ActionResult GetVitualPhoneDetailList(int page = 1, int pageSize = 15, string directorId = null,int? status=null)
        {
            int skip = (page - 1) * pageSize;
            var res = dm.GetAllPhoneList(directorId);
            if (status != null)
            {
                res = res.FindAll(r => r.AssignStatus == (AssignStatus)status);
            }
            var res2 = res.Skip(skip).Take(pageSize);
            return Json(res2,JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetVitualPhoneDetailListCount(string directorId = null, int? status = null)
        {
            var res = dm.GetAllPhoneList(directorId,false);
            if (status != null)
            {
                res = res.FindAll(r => r.AssignStatus == (AssignStatus)status);
            }
            return Json(res.Count);
        }
    }
}
